package com.aoxiang.zbox.controller;

import com.aoxiang.zbox.common.model.Result;
import com.aoxiang.zbox.model.dto.LoginUser;
import com.aoxiang.zbox.model.dto.RegisterUser;
import com.aoxiang.zbox.model.vo.LoginUserVO;
import com.aoxiang.zbox.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 *
 * @author: aoxiang
 * @create: 2025-03-29 10:52
 **/

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userService;

    // 注册用户
    @PostMapping("/register")
    public Result<Long> register(@RequestBody @Validated RegisterUser user) {
        return Result.success(userService.register(user));
    }

    @PostMapping("/login")
    public Result<LoginUserVO> login(@RequestBody @Validated LoginUser user) {
        return Result.success(userService.login(user));
    }

    @GetMapping("/logout")
    public Result<String> logout(@RequestHeader("Authorization") String authorization) {
        userService.logout(authorization);
        return Result.success("退出成功");
    }

    // 注销
    @GetMapping("/writeOff")
    public Result<String> writeOff() {
        userService.writeOff();
        return Result.success("注销成功");
    }

}
